package test1;

import java.util.HashMap;
import java.util.Map;

class ListNode {
    int val;
    ListNode next = null;

    ListNode(int val) {
        this.val = val;
    }
}


public class Solution {
    public static ListNode deleteDuplication(ListNode pHead) {
        if(pHead==null){
            return null;
        }
        Map<Integer,Integer> map=new HashMap<>();
        ListNode start=pHead;
        while(start!=null){
            if(map.containsKey(start.val)){
                map.put(start.val,1+map.get(start.val));
            }else{
                map.put(start.val,1);
            }
            start=start.next;
        }
        ListNode preHead=new ListNode(0);
        preHead.next=pHead;
        ListNode cur=pHead;
        while(cur!=null){
            if(map.get(cur.val)!=1){
                preHead.next=cur.next;
            }
            preHead=preHead.next; cur=cur.next;
        }

        return pHead;
    }

    public static void main(String[] args) {
        deleteDuplication(new ListNode(1));
    }
}
